<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/9
 * Time: 10:54
 */

/**
 * Class RedisHandle
 *
 */
class RedisHandle  {
    const ttl = 86400;

    private static $_redis = NULL;

    private static $_prefix = 'file_service_';

    public static function getInstance()
    {
        $ci = & get_instance();
        $ci->config->load('redis', TRUE);
        if (self::$_redis === NULL)
        {
            self::$_redis = new Redis();
            self::$_redis->connect($ci->config->item('host', 'redis'), $ci->config->item('port', 'redis'));
        }

        return self::$_redis;

    }

    /**
     * 给服务redis缓存加上key
     * @param $key
     * @return string
     */
    public static function getKey($key)
    {
        return self::$_prefix . $key;
    }

    /**
     * 关闭redis
     */
    public static function close(){
        if (self::$_redis)
        {
            self::$_redis->close();
            self::$_redis = NULL;
        }
    }
}